/**
 * This file is part of the CAKIS project.
 * 
 * Copyright (c) 2009-2010 - Florian Arndt, Christian Kerl
 * 
 * @license GNU Lesser General Public License v3 <http://www.opensource.org/licenses/lgpl-3.0.html>
 * @since   04.05.2010
 * @version SVN: $Id: AllProductListsForm.java 111 2010-05-07 10:50:22Z f.aarndt@web.de $
 */

package org.cakis.client.forms;

import java.rmi.RemoteException;

import javax.microedition.lcdui.List;

import org.cakis.client.CakisMIDlet;
import org.cakis.client.commands.ProductListCommand;
import org.cakis.client.commands.ResumeCommand;
import org.cakis.webservice.ProductList;

/**
 * AllProductListsForm
 *
 * @author Florian Arndt
 */
public class AllProductListsForm extends AbstractList {
	private ProductList[] allProductLists;

	public AllProductListsForm(CakisMIDlet midlet) {
		super("Alle Einkaufslisten", List.IMPLICIT, midlet);
		try {
			allProductLists = midlet.getService().getProductLists();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		
		String[] productListsString = new String[allProductLists.length];
		for (int i = 0; i < allProductLists.length; i++) {
			productListsString[i] = allProductLists[i].getName();
		}
		
	    for (int i = 0; i < productListsString.length; i++) {
	    	this.append(productListsString[i], null);
	    }
	    
	    this.addCommand(new ProductListCommand(midlet, this));
	    this.addCommand(new ResumeCommand(midlet));
		midlet.display(this);
	}
	
	public Long getSelectedProductListId () {
		return allProductLists[this.getSelectedIndex()].getId();
	}
}
